import Vue from 'vue'
import Router from 'vue-router'
import index from '@/view/index'
import login from '@/view/login'
/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index,
      redirect: {name: 'main'},
      children: [
        {
          path: '/main',
          name: 'main',
          component: () => {
            return import('@/view/main/main')
          }
        },
        {
          path: '/leave',
          name: 'leave',
          component: () => {
            return import('@/view/leave/leave')
          }
        },
        {
          path: '/rent',
          name: 'rent',
          component: () => {
            return import('@/view/rent/rent')
          }
        },
        {
          path: '/inventory',
          name: 'inventory',
          component: () => {
            return import('@/view/inventory/inventory')
          }
        },
        {
          path: '/classify',
          name: 'classify',
          component: () => {
            return import('@/view/classify/classify')
          }
        },
        {
          path: '/flower',
          name: 'flower',
          component: () => {
            return import('@/view/flower/flower')
          }
        },
        {
          path: '/client',
          name: 'client',
          component: () => {
            return import('@/view/client/client')
          }
        },
        {
          path: '/userMgr',
          name: 'userMgr',
          component: () => {
            return import('@/view/userMgr/userMgr')
          }
        },
        {
          path: '/log',
          name: 'log',
          component: () => {
            return import('@/view/log/log')
          },
          redirect: {name: 'operationlog'},
          children: [
            {
              path: '/loginlog',
              name: 'loginlog',
              component: () => {
                return import('@/view/log/loginlog')
              }
            },
            {
              path: '/operationlog',
              name: 'operationlog',
              component: () => {
                return import('@/view/log/operationlog')
              }
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: login
    }
  ]
})
